package com.gml.design.other.strategy;

/**
 * @ClassName : Sorter
 * @Description : 排序
 * @Author : gml
 * @Date: 2021-04-02 16:33
 */
public class Sorter {

    public static void sort(Comparable[] arr){
        for (int i = 0; i < arr.length-1; i++) {
            int minPos = i;
            for (int j = i + 1; j < arr.length; j++) {
                minPos = arr[j].compareTo(arr[minPos]) == -1 ? j : minPos;
            }

            swap(arr, i , minPos);
        }
    }

    public static void swap(Comparable[] arr, int i, int j){
        Comparable temp = arr[j];
        arr[j] = arr[i];
        arr[i] = temp;
    }

}
